<?php
namespace app\index\controller;
use think\Controller;
use think\Db;
use think\Session;
class Gw extends Controller
{
    public function index()
    {
       
        $gw = Db::table('position')
        ->alias('a')
        ->join('company c','c.company_id = a.company_id')
        ->where('position_status',0)
        ->order('position_id desc')
        ->paginate(5);
        
        
        $this->assign("gw",$gw);
        $page = $gw->render();
        // dump($gw);
        // exit;
        $this->assign('page', $page);
        $gw1 = Db::table('position')
        ->alias('a')
        ->join('company c','c.company_id = a.company_id')
        ->where('position_status',0)
        ->order('position_id desc')
        ->paginate(3);
        
        
        $this->assign("gw1",$gw1);
       return $this->fetch();
    }
    public function index1($id)
    {
       
        $gw = Db::table('position')
        ->alias('a')
        ->join('company c','c.company_id = a.company_id')
        ->where('position_status',0)
        ->where('joptype_id',$id)
        ->order('position_id desc')
        ->paginate(5);
        
        
        $this->assign("gw",$gw);
        $page = $gw->render();
        // dump($page);
        // exit;
        $this->assign('page', $page);
        $gw1 = Db::table('position')
        ->alias('a')
        ->join('company c','c.company_id = a.company_id')
        ->where('position_status',0)
        ->order('position_id desc')
        ->paginate(3);
        
        
        $this->assign("gw1",$gw1);
       return $this->fetch();
    }
    public function gwdetails($position_id)
    {
        $a = Session::has('user_id');
        if($a == null)
        {
            $gw = Db::table('position')
                ->alias('a')
                ->join('company c','c.company_id = a.company_id')
                ->where('position_id',$position_id)
                ->where('position_status',0)
                ->select();
            $this->assign("gw",$gw);
            $jl = 0;
            $this->assign("jl",$jl);
            return $this->fetch();
        }
        else
        {
            $gw = Db::table('position')
        ->alias('a')
        ->join('company c','c.company_id = a.company_id')
        ->where('position_id',$position_id)
        ->where('position_status',0)
        ->select();
        $this->assign("gw",$gw);
        $user_id = Session::get("user_id");
        $jl = Db::table('resume')
        ->where('user_id',$user_id)
        ->where('resume_status',0)
        ->select();
        // dump($jl);
        // exit;
       $this->assign("jl",$jl);
      return $this->fetch();
        }
        
    }
    public function collect($position_id)
    {
        $user_key = Session::has('user_id');
        if(!$user_key)
        {
            return $this->error('请登录后，再操作！');
        }
        $user_id = Session::get("user_id");
        $data = [
            "user_id"=>$user_id,
            "position_id"=>$position_id,
            // "position_time"=>date('Y-m-d H:i:s',time()),
        ];
        // dump($data);
        // exit;
        $cc = Db::name('collect')->where('user_id',$user_id)->where('position_id',$position_id)->find();
        // dump($res);
        // exit;
        if($cc==null){

            $res = Db::table('collect')->insert($data);
                if($res)
                {
                    return $this->success('收藏成功','gw/index');
                }
                else
                {
                    return $this->error('失败');
                }
            
        }else{
            return $this->error('已经收藏过啦');
        }
    }
    public function toujl()
    {
        $user_key = Session::has('user_id');
        if(!$user_key)
        {
            return $this->error('请登录后，再操作！');
        }
        $user_id = Session::get("user_id");
        $position_id = input('position_id');
        $data = [
            "user_id"=>$user_id,
            "resume_id"=>input('resume_id'),
            "send_too"=>0,
            "send_status"=>0,
            "position_id"=>input('position_id'),
            "send_time"=>date('Y-m-d H:i:s',time()),

        ];
        // dump($data);
        // exit;
        $cc = Db::name('send')->where('user_id',$user_id)->where('position_id',$position_id)->find();
        // dump($res);
        // exit;
        if($cc==null){

            $res = Db::table('send')->insert($data);
                if($res)
                {
                    return $this->success('投递成功','gw/index');
                }
                else
                {
                    return $this->error('失败');
                }
            
        }else{
            return $this->error('已经投递过啦');
        }
    }
}
